package com.realbrand.net.realbrandpay.ui.activity.wallet.personer;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.realbrand.net.realbrandpay.R;
import com.realbrand.net.realbrandpay.base.BaseActivity;
import com.realbrand.net.realbrandpay.ui.activity.SetPersonImageActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Administrator on 2017/7/10.
 */

public class PersonMessageActivity extends BaseActivity {
    @BindView(R.id.person_toolbar)
    Toolbar personToolbar;
    @BindView(R.id.personMessage_liner)
    LinearLayout personMessageLiner;
    //上传图像的请求码
    public static final int SETIMAGE_CODE = 0x001;
    //设置用户名的请求码
    public static final int SETUSERNAME_CODE = 0x002;
    //选择城市请求码
    public static final int CHOOSE_PROVINCE = 0x003;

    @BindView(R.id.personMessage_cv_image)
    CircleImageView personMessageCvImage;
    @BindView(R.id.personMessage_liner_userName)
    LinearLayout personMessageLinerUserName;
    @BindView(R.id.personMessage_liner_region)
    LinearLayout personMessageLinerRegion;
    @BindView(R.id.personMessage_tv_userName)
    TextView personMessageTvUserName;
    @BindView(R.id.personMessage_tv_province)
    TextView personMessageTvProvince;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        personToolbar.setTitle("");
        personToolbar.setNavigationIcon(R.drawable.ic_back);
        setSupportActionBar(personToolbar);
        personToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        setOnClick();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.personalinformation_activity;
    }

    @Override
    protected void setOnClick() {
        personMessageLiner.setOnClickListener(this);
        personMessageLinerUserName.setOnClickListener(this);
        personMessageLinerRegion.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //点击上传图像
            case R.id.personMessage_liner:
                startActivityForResult(new Intent(this, SetPersonImageActivity.class), SETIMAGE_CODE);
                break;
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                //接收到头像图片
                case SETIMAGE_CODE:
                    Bitmap bitmap = data.getParcelableExtra("bitmap");
                    Drawable drawable = new BitmapDrawable(bitmap);
                    personMessageCvImage.setImageDrawable(drawable);
                    break;
            }

        }
    }
}
